package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.util.ShiroUtils;
import com.dongdongshop.data.Result;
import com.dongdongshop.em.ResultEnum;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.SellerService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("registerController")
public class RegisterController {

    @Reference
    private SellerService sellerService;

    @RequestMapping("register")
    public String register(){
        return "register";
    }

    @RequestMapping("getRegister")
    @ResponseBody
    public Result getRegister(TbSeller tbSeller){
        try{
            String password = "1234";
            tbSeller.setStatus("0");
            String s1 = ShiroUtils.generateSalt(6);
            System.out.println(s1);
            String s = ShiroUtils.encryptPassword("MD5", password, s1, 10);
            System.out.println(s);
            //盐  字段
            tbSeller.setBrief(s1);
            tbSeller.setPassword(s);
            Integer i =sellerService.register(tbSeller);
            return Result.response(ResultEnum.SUCCESS).setData(i);
        }catch (Exception e){
            return Result.response(ResultEnum.ERROR).setData(e);
        }
    }
}
